package com.study.config;

import io.milvus.client.MilvusServiceClient;
import io.milvus.param.ConnectParam;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

@Configuration
public class MilvusClientConfig {

    @Value("${milvus.host}")
    public String HOST;

    @Value("${milvus.port}")
    public int PORT;

    @Value("${milvus.connectTimeout}")
    public int CONNECT_TIMEOUT;

    @Value("${milvus.TIMEOUT_UNIT}")
    public TimeUnit TIMEOUT_UNIT;

    @Bean
    public MilvusServiceClient milvusClient() {
        MilvusServiceClient client = new MilvusServiceClient(
                ConnectParam.newBuilder()
                        .withHost(HOST)
                        .withPort(PORT)
                        .withAuthorization("")
                        .withConnectTimeout(CONNECT_TIMEOUT, TIMEOUT_UNIT)
                        .build());
        return client;
    }
}
